//
//  Singleton.m
//  MyDemo
//
//  Created by JuYuFeng on 16/12/9.
//  Copyright © 2016年 macOS. All rights reserved.
//
#import "AFNetworking.h"
#import "Singleton.h"
#import "MBProgressHUD.h"
#import "WCPopupLayerManager.h"
#import "FastCoder.h"
static Singleton *center = nil;

@implementation Singleton
//单例方法
+(instancetype)sharedSingleton{
    
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        
        center = (Singleton *)@"Singleton";
        center = [[Singleton alloc] init];
    });
    
    // 防止子类使用
    NSString *classString = NSStringFromClass([self class]);
    if ([classString isEqualToString:@"Singleton"] == NO) {
        
        NSParameterAssert(nil);
    }
    return center;
}

//初始化方法
- (instancetype)init{
    NSString *string = (NSString *)center;
    if ([string isKindOfClass:[NSString class]] == YES && [string isEqualToString:@"Singleton"]) {
        self = [super init];
        if (self) {
            // 防止子类使用
            NSString *classString = NSStringFromClass([self class]);
            if ([classString isEqualToString:@"Singleton"] == NO) {
                NSParameterAssert(nil);
            }
        }
        
        Log(@"单例");
        NSString *temp = [[NSUserDefaults standardUserDefaults]objectForKey:@"token"];
        if (!IsNilString(temp) && ![temp isEqualToString:@"logout"] && temp.length>10) {
            _isLogin = YES;
            NSData *userInfoData = [[NSUserDefaults standardUserDefaults]objectForKey:@"userInfoData"];
            _userInfoModel = (UserInfoModel *)[FastCoder objectWithData:userInfoData];
        }
        
        
        return self;
    } else {
        return nil;
    }

}









@end




















